#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
const int N = 35;
int a[N], n;
vector<int> G[N];
int getMinIdx(int l, int r) {
    int p = l;
    rep(i, l + 1, r) if (a[i] < a[p]) p = i;
    return p;
}
void build(int fa, int l, int r) {
    if (l >= r || l < 1 || r > n) return;
    if (l < fa) {
        int lson = getMinIdx(l, fa - 1);
        G[fa].push_back(lson);
        build(lson, l, fa - 1);
    }
    if (r > fa) {
        int rson = getMinIdx(fa + 1, r);
        G[fa].push_back(rson);
        build(rson, fa + 1, r);
    }
}
int main() {
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    int root = getMinIdx(1, n);
    build(root, 1, n);
    vector<int> ans;
    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        ans.push_back(now);
        for (int x : G[now]) q.push(x);
    }
    for (int i = 0; i < n; ++i) {
        cout << a[ans[i]];
        if (i != n - 1)
            cout << ' ';
        else
            cout << '\n';
    }
    return 0;
}